package com.dp.study.WebSocket.service;

import com.dp.study.WebSocket.bean.InMessage;
import com.dp.study.WebSocket.bean.OutMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

/**
 * SimpMessagingTemplate  简单消息模板
 * Created by IntelliJ IDEA
 * User: DengPeng
 * Date: 2019/5/15 ,
 * Time: 19:03 ,
 * Email:dp9212@163.com .
 */
@Service
public class SendMessageService {

    @Autowired
    private SimpMessagingTemplate template;

    /**
     * 利用简单消息模板发送消息
     * @param topic     消息发送地址
     * @param message   消息内容
     * @throws InterruptedException
     */
    public void sendTopicMessage(String topic, InMessage message) throws InterruptedException{

        for(int i=0; i<5; i++){
            Thread.sleep(500L);
            template.convertAndSend(topic, new OutMessage(message.getContent()+i));
        }

    }

}
